package com.hydra.baseui.recyclerlist;

import androidx.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.ViewGroup;

public class ResourceItemHolderBuilder implements ItemHolderBuilder {

	private int[] mResources;

	public ResourceItemHolderBuilder(int[] resources) {
		mResources = resources;
	}

	@Override
	@Nullable
	public BaseItemHolder buildItem(ViewGroup parent, int type) {
		try {
			return new BaseItemHolder(LayoutInflater.from(parent.getContext())
					.inflate(mResources[type], parent, false));
		} catch (Exception e) {
			Log.e(getClass().getSimpleName(), "build Item failed : " + e.toString());
			return null;
		}
	}

	@Override
	public void release() {
		mResources = null;
	}
}
